package org.droidexpress.tools;

import java.io.Serializable;
import java.util.List;

import org.droidexpress.R;
import org.droidexpress.data.Destinataire;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.TextView;

public class DestinataireAdapter extends BaseAdapter implements Serializable {

	private static final long serialVersionUID = 1L;
	List<Destinataire> listeDest;
	LayoutInflater inflater;
	
	public DestinataireAdapter(Context context, List<Destinataire> nListeDest)
	{
		inflater = LayoutInflater.from(context);
		listeDest = nListeDest;
	}
	
	public int getCount() {
		// TODO Auto-generated method stub
		return listeDest.size();
	}
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return listeDest.get(position);
	}
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder;
		if(convertView == null)
		{
			holder = new ViewHolder();
			convertView = inflater.inflate(R.layout.listdestination, null);
			holder.tvDest = (TextView) convertView.findViewById(R.id.listDestTitre);
			holder.tvDetail = (TextView) convertView.findViewById(R.id.listDestDetail);
			holder.cbDone = (CheckBox) convertView.findViewById(R.id.listDestDone);
			convertView.setTag(holder);
		}
		else
		{
			holder = (ViewHolder) convertView.getTag();
		}
		
		holder.tvDest.setText(listeDest.get(position).nom);
		holder.tvDetail.setText(listeDest.get(position).rue + ", " + listeDest.get(position).cp + " " + listeDest.get(position).ville);
		holder.cbDone.setChecked(listeDest.get(position).done);
		return convertView;
	}
	
	public class ViewHolder{
		TextView tvDest;
		TextView tvDetail;
		CheckBox cbDone;
	}
	
}
